// pages/historyOperation/historyOperation.js
const app = getApp();
Page({

 
  data: {
    records: []
  },
  

  onLoad: function (options) {
    var records=[];
    var record=[{ date: '6月17日' }, { time: '10:00-11:00' }, { room: 'c10-5楼' }];  //用于存放服务器获取的数组
    records.push(record);
    records.push(record);
    records.push(record); 
    records.push(record);     //本地显示的数组
    this.setData({
      "records":records,
    })
    
  },

  onShow:function(){
    this.getRecords();

  },

  onReady: function () {

  },


  getRecords: function () {
    var that=this
    wx.request({
      url: 'https://dorm.dormassistant.wang:8080/record/queryRecordByUserId',
      data: {
        userId: wx.getStorageSync('openid')
      },
      method: "GET",
      success: function (res) {
        var tempRecords = res.data.records;
        var tempRomms = res.data.roomList;
        var recordList=[];
        console.log(res.data)
        for(var i=0;i<tempRecords.length;i++){
          var c = app.extend(tempRecords[i], tempRomms[i]);
          var time = tempRecords[i].time
          var begin = tempRecords[i].begin
          var end = tempRecords[i].end
          c.time = time.substring(0, 10)
          c.begin = begin
          c.end = end
          recordList.push(c);
        }
        that.setData({
          recordList: recordList,
        });
        console.log(that.data);
      },
    });
  }
  
})
